package com.fruit.app.action.index.screen;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.jsoup.Connection.Request;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	
	private String uname;
	
	private String password;
	
	private Integer flag;
	

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}

	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String login(){
		Map<String, String> map=new HashMap();
		map.put("admin", "admin");
		map.put("heweidong", "123456");
		map.put("xumin", "123456");
		map.put("huhui", "123456");
		map.put("yujinglun", "123456");
		if (BooleanUtils.isFalse(StringUtils.isBlank(uname) || StringUtils.isBlank(password))) {
			if(map.containsKey(uname.trim())&&map.containsValue(password.trim())){
				ActionContext.getContext().getSession().put("user", uname);
				return SUCCESS;
			}else{
				setFlag(1);
				return "tologin";
			}
		}
		ActionContext.getContext().getSession().put("user", "");
		return  "tologin";
	}
	
}
